/**
 ****************************************************************************************
 *
 * @file sadc.h
 *
 * @brief SADC(ADC) Interface of Application
 *
 * @data 2022.05.13
 *
 ****************************************************************************************
 */

#ifndef SADC_H_
#define SADC_H_

#include <stdint.h>

typedef enum
{
    ADC_CLK_DIV_NONE = 0x00, // no divided
    ADC_CLK_DIV2     = 0x01, // divided by 2
    ADC_CLK_DIV4     = 0x02, // divided by 4
    ADC_CLK_DIV8     = 0x03, // divided by 8
    ADC_CLK_DIV16    = 0x04, // divided by 16
    ADC_CLK_DIV32    = 0x05, // divided by 32
    ADC_CLK_DIV64    = 0x06, // divided by 64
    ADC_CLK_DIV128   = 0x07, // divided by 128
    ADC_CLK_DIV256   = 0x08, // divided by 256
    ADC_CLK_DIV512   = 0x09, // divided by 512
    ADC_CLK_DIV1024  = 0x0A, // divided by 1024
    ADC_CLK_DIV2048  = 0x0B, // divided by 2048
    ADC_CLK_DIV4096  = 0x0C, // divided by 4096
} ADC_CLK_Div_Type;

typedef enum
{
    ADC_CLK_CONV_AT_NEGEDGE = 0, // conversion at negedge of clk
    ADC_CLK_CONV_AT_POSEDGE = 1, // conversion at posedge of clk
} ADC_CLK_Phase_Type;

typedef enum
{
    ADC_SINGLE_ENDED_INPUT = 0, // single ended input mode
    ADC_DIFFERENTIAL_INPUT = 1, // differential input mode
} ADC_Input_Mode_Type;

typedef enum
{
    ADC_VREF_SEL_VBG = 0x01, // reference voltage bandgap 1.2v
    ADC_VREF_SEL_VDD = 0x02, // reference vlotage vdd33
    ADC_VREF_SEL_EXT = 0x03, // reference external pad(vref pad)
} ADC_Vref_Sel_Type;

typedef enum
{
    ADC_CAP_CAL_LVL0 = 0x00, // most precision but narrow range
    ADC_CAP_CAL_LVL1 = 0x01, //
    ADC_CAP_CAL_LVL2 = 0x02, //
    ADC_CAP_CAL_LVL3 = 0x03, //
    ADC_CAP_CAL_LVL4 = 0x04, //
    ADC_CAP_CAL_LVL5 = 0x05, //
    ADC_CAP_CAL_LVL6 = 0x06, //
    ADC_CAP_CAL_LVL7 = 0x07, // widest range but less precision
} ADC_Cap_Cal_Lvl_Type; 

// ADC Common mode voltage bias current selected
// VCM
typedef enum
{
    ADC_COMMON_MODE_CUR_SEL0 = 0x00, // 0.75uA
    ADC_COMMON_MODE_CUR_SEL1 = 0x01, // 1.50uA
    ADC_COMMON_MODE_CUR_SEL2 = 0x02, // 2.25uA
    ADC_COMMON_MODE_CUR_SEL3 = 0x03, // 3.00uA(default)
    ADC_COMMON_MODE_CUR_SEL4 = 0x04, // 3.75uA
    ADC_COMMON_MODE_CUR_SEL5 = 0x05, // 4.50uA
    ADC_COMMON_MODE_CUR_SEL6 = 0x06, // 5.25uA
    ADC_COMMON_MODE_CUR_SEL7 = 0x07, // 6.00uA
} ADC_Common_Mode_Cur_Sel_Type;

typedef enum
{
    ADC_COMP_CUR_SEL0 = 0x00, // 15uA
    ADC_COMP_CUR_SEL1 = 0x01, // 30uA
    ADC_COMP_CUR_SEL2 = 0x02, // 45uA
    ADC_COMP_CUR_SEL3 = 0x03, // 60uA(default)
    ADC_COMP_CUR_SEL4 = 0x04, // 75uA
    ADC_COMP_CUR_SEL5 = 0x05, // 90uA
    ADC_COMP_CUR_SEL6 = 0x06, // 105uA
    ADC_COMP_CUR_SEL7 = 0x07, // 120uA
} ADC_Comparator_Sel_Type;

typedef enum
{
    ADC_SINGLE_CONVER_MODE =   0x00, // single convertion mode
    ADC_CONTINUE_CONVER_MODE = 0x01, // continous convertion
} ADC_Conv_Mode_Type;

typedef enum
{
    ADC_INBUF_ON  = 0x00, // throuth input buffer
    ADC_INBUF_OFF = 0x01, //bypass input buffer
} ADC_Input_Buff_Type;

typedef enum
{
    ADC_SAMPLE_MODE_NORMAL = 0,
    ADC_SAMPLE_MODE_RSSI,
    ADC_SAMPLE_MODE_FILTER,
    ADC_SAMPLE_MODE_ADTMR_TRIG,
} ADC_Sample_Mode;

/********************* ADC Channel *********************/
// ADC Single ended channel
#define ADC_CHN_AIN0   0x00
#define ADC_CHN_AIN1   0x01
#define ADC_CHN_AIN2   0x02
#define ADC_CHN_AIN3   0x03
#define ADC_CHN_AIN4   0x04
#define ADC_CHN_AIN5   0x05
#define ADC_CHN_AIN6   0x06
#define ADC_CHN_AIN7   0x07
#define ADC_CHN_AIN8   0x08


void adc_mic_init(void);

#endif // SADC_H_
